//
//  MainVC_Mine.m
//  liBaQiang
//
//  Created by 奇林刘 on 2018/10/11.
//  Copyright © 2018年 liu. All rights reserved.
//

#import "MainVC_Mine.h"
#import "MainVC_Mine_CompanyCard.h"
#import "MainVC_Mine_Button.h"

@interface MainVC_Mine ()

@property (nonatomic, strong) MainVC_Mine_CompanyCard *companyCard;
@property (nonatomic, strong) NSMutableArray <MainVC_Mine_Button *> *buttons;

@end

@implementation MainVC_Mine

- (void)configSelf {
    self.view.fp_backgroundColor(HexadecimalColor(@"F5F6F8"));
    [self changeScrollMode:ScrollModePortrait];
}

- (void)allocateComponents {
    [self allocateCompanyCard];
    [self allocateButtons];
}

- (void)allocateCompanyCard {
    self.companyCard = [[MainVC_Mine_CompanyCard alloc] init];
    [self.scrollContentView addSubview:self.companyCard];
    [self.companyCard mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.scrollContentView).offset(RPX(15));
        make.centerX.equalTo(self.scrollContentView);
    }];
}

- (void)allocateButtons {
    self.buttons = [NSMutableArray array];
    NSDictionary *MainVC_Mine_Property = [HandyMethods getPlistDicByName:@"MainVC_Mine_Property"];
    NSArray *ButtonGroups = MainVC_Mine_Property[@"ButtonGroups"];
    for (int section=0; section<ButtonGroups.count; section++) {
        NSArray *rows = ButtonGroups[section];
        for (int row=0; row<rows.count; row++) {
            NSString *logo = rows[row][@"image"];
            NSString *title = rows[row][@"title"];
            MainVC_Mine_Button *previousButton = (self.buttons.count > 0) ? self.buttons.lastObject : nil;
            MainVC_Mine_Button *currentButton = [[MainVC_Mine_Button alloc] initWithLogoImageName:logo title:title];
            [currentButton addTarget:[HandyMethods getViewControllerForView:currentButton] action:NSSelectorFromString(rows[row][@"method"]) forControlEvents:UIControlEventTouchUpInside];
            [self.scrollContentView addSubview:currentButton];
            [self.buttons addObject:currentButton];
            
            [currentButton mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(self.scrollContentView);
                if (section==0 && row==0) {
                    make.top.equalTo(self.companyCard.mas_bottom).offset(RPX(15));
                } else if (row==0) {
                    make.top.equalTo(previousButton.mas_bottom).offset(RPX(11));
                } else {
                    make.top.equalTo(previousButton.mas_bottom);
                }
                if (section==ButtonGroups.count-1 && row==rows.count-1) {
                    make.bottom.equalTo(self.scrollContentView).offset(RPX(-15));
                }
            }];
        }
    }
    
}


@end
